package com.unipay.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.unipay.common.result.Result;
import com.unipay.model.user.UserInfo;
import com.unipay.user.service.UserInfoService;
import com.unipay.vo.user.UserInfoQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Project: yitong_parent
 * @Author: C.yu
 * @Time: 2023-05-01 09:08:01
 * @Desc: TODO  用户管理admin
 */
@Api(tags = "用户管理API")
@RestController
@RequestMapping("/admin/user")
public class UserController {
    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation("用户分页列表")
    @GetMapping("userList/{page}/{limit}")
    public Result userList(
            @PathVariable Long page,
            @PathVariable Long limit,
            UserInfoQueryVo userInfoQueryVo
    ) {
        Page<UserInfo> userInfoPage = new Page<>(page, limit);
        IPage<UserInfo> pageModel = userInfoService.selectPage(userInfoPage, userInfoQueryVo);
        return Result.ok(pageModel);
    }

    @ApiOperation("用户详情")
    @GetMapping("show/{userId}")
    public Result show(@PathVariable Long userId) {
        Map<String, Object> map = userInfoService.show(userId);
        return Result.ok(map);
    }

    @ApiOperation("用户锁定")
    @GetMapping("lock/{userId}/{status}")
    public Result lock(@PathVariable Long userId, @PathVariable Integer status) {
        Integer b = userInfoService.lock(userId, status);
        return Result.ok(b);
    }

    //认证审批  2通过  -1不通过
    @ApiOperation("认证审批")
    @GetMapping("approval/{userId}/{authStatus}")
    public Result approval(
            @PathVariable Long userId,
            @PathVariable Integer authStatus
    ) {
        Boolean approval = userInfoService.approval(userId, authStatus);
        return Result.ok(approval);
    }
}
